fix(ios): apply obliqueness if italics are not supported - #745
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves iOS italic rendering by applying an NSObliqueness fallback when the active font (or its italic face) can’t render italic glyphs (notably for CJK), and introduces a style-priority mechanism so italics can be applied after font-changing inline styles.
Changes:
- Added
ItalicUtilsto classify grapheme clusters and apply either a real italic font or anNSObliquenessfallback per segment. - Introduced
stylingPriorityonStyleBaseand used it to deterministically order inline style application (with italics opting to apply last). - Updated inline-style application ordering in both
TextHtmlParserandInputAttributesManager.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| ios/utils/ItalicUtils.mm | New per-cluster italic/oblique application logic using CoreText glyph coverage checks. |
| ios/utils/ItalicUtils.h | Public interface for applying italic logic to an NSTextStorage range. |
| ios/textHtmlParser/TextHtmlParser.mm | Sorts deferred inline style applications by stylingPriority. |
| ios/styles/ItalicStyle.mm | Switches italic styling to use ItalicUtils and sets priority to apply later. |
| ios/interfaces/StyleBase.mm | Adds default stylingPriority implementation. |
| ios/interfaces/StyleBase.h | Declares stylingPriority on the base style interface. |
| ios/inputAttributesManager/InputAttributesManager.mm | Orders style re-application using paragraph-first + stylingPriority. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
ios/utils/ItalicUtils.mm:129
[NeutralCharacters() invertedSet]allocates a new character set each timekindForCluster:runs. This is called per composed character sequence, so it can create avoidable churn on large strings. Cache the inverted set once (similar toNeutralCharacters()) and reuse it.
if ([cluster rangeOfCharacterFromSet:[NeutralCharacters() invertedSet]]
.location == NSNotFound) {
return ItalicKindNone;
}
| - (BOOL)isParagraph; | ||
| - (BOOL)needsZWS; | ||
| - (BOOL)appliesStylingToTyping; | ||
| - (NSInteger)stylingPriority; |
There was a problem hiding this comment.
There wili be conflict with customStyle I applied there stylePriority property in StyleBase: https://github.com/software-mansion/react-native-enriched-html/pull/641/changes#diff-7d290ee647218a0cde80f6b721d4476384026b9a060c8906cc4964c36f28ba0dR43
| // Sort style types so paragraph styles come first. Their broad visual | ||
| // attributes (e.g. foreground color, font) are laid down before inline | ||
| // styles override them on their specific sub-ranges. | ||
| // styles override them on their specific sub-ranges. Inline styles among |
There was a problem hiding this comment.
And I also added sorting in here by stylePriority in customStyle. And that would fix problem with inline style applied in wrong order because there inline styles are applied as last. https://github.com/software-mansion/react-native-enriched-html/pull/641/changes#diff-f0ba56d65d53cacb60b6d3b46e66fc464076119a4d5df36d92fcdd98b2a95847R98
Summary
this fixes #739
NSObliquenessattribute is applied, when given font does not support proper italicsstylingPrioritytrait for base styles, so italics can be applied lastTest Plan
Paste some non-latin characters, e.g. "冰淇淋", apply the italic style, everything should look as expected
Screenshots / Videos
The italics are now properly applied
cjkitalics.mov
Compatibility
Checklist